﻿using AutoMapper;
using Blazor.ECharts.Options.Enum;
using System.Text.Json;
using TrackSystem.Contracts;
using TrackSystem.Entities.Dtos.Channel;
using TrackSystem.Entities.Dtos.Equip;

namespace TrackSystem.UI.Server.HttpRepository.Equip
{
    public class EquipHttpRepository : HttpRepository<EquipDto, EquipWithSensorsDto>, IEquiplHttpRepository
    {
        private readonly HttpClient client;
        private readonly IMapper mapper;

        public EquipHttpRepository(HttpClient client, IMapper mapper) : base(client, mapper) 
        {
            this.client = client;
            this.mapper = mapper;
            Name = "equip";
        }

        public async Task<IEnumerable<EquipWithSensorsDto>> GetAllWithSensors()
        {
            var response = await client.GetAsync("api/equip/all/sensors");
            var content = await response.Content.ReadAsStringAsync();
            var Items = JsonSerializer.Deserialize<IEnumerable<EquipWithSensorsDto>>(
                content,
                new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
            return Items ??= [];
        }
    }

}
